﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using com.cruxomatic.controllers;
using com.cruxomatic.DTOs;
using com.cruxomatic.views.Administration;
using com.cruxomatic.controllers.Administration;
using com.cruxomatic.DTOs.Configuration;

public partial class Administration_ResetPassword : BaseView, IResetPassword
{
    ResetPasswordController _controller = null;

    protected void Page_Load(object sender, EventArgs e)
    {
        _controller = new ResetPasswordController(this);
        _controller.InitView(IsPostBack);

        if (!Page.IsPostBack)
                SetSiteMap();
    }

    #region Site Map
    private void SetSiteMap()
    {
        string query = Request.Url.Query;
        UrlTreeNodeItems.ResetPassword = UrlTreeNodeItems.CreateNode("Reset Password",
                                                                          "/Administration/ResetPassword.aspx" + query,
                                                                          "ManageUserDetail",
                                                                          UrlTreeNodeItems.Admin);
        if (Request.UrlReferrer != null)
        {
            if (UrlTreeNodeItems.ManageUser != null)
                if (Request.UrlReferrer.ToString().Contains(UrlTreeNodeItems.ManageUser.Url))
                    UrlTreeNodeItems.ResetPassword = UrlTreeNodeItems.CreateNode("Reset Password",
                                                                                 "/Administration/ResetPassword.aspx" + query,
                                                                                 "ManageUserDetail2",
                                                                                 UrlTreeNodeItems.ManageUser);
        }
        UrlTreeNodeItems.SetSiteNavigation(PageSiteMap, UrlTreeNodeItems.ResetPassword);
    }
    #endregion

    #region IResetPassword Members

    public int UserID
    {
        get { return int.Parse(Request.Params["id"].ToString()); }
    }

    public string NewPassword
    {
        get
        {
            return txtNewPassword.Text;
        }
        set
        {
            txtNewPassword.Text = value;
        }
    }

    public string ConfirmedNewPassword
    {
        get
        {
            return txtConfirmedNewPassword.Text;
        }
        set
        {
            txtConfirmedNewPassword.Text = value;
        }
    }

    public ErrorInformation ErrorDetails
    {
        get
        {
            return pnlError.ErrorInformation;
        }
        set
        {
            pnlError.ErrorInformation = value;
        }
    }

    public string CurrentPassWord
    {
        get
        {
            return txtCurrentPassword.Text;
        }
        set
        {
            txtCurrentPassword.Text = value;
        }
    }

    #endregion
    protected void btnSave_Click(object sender, EventArgs e)
    {
        _controller.ResetPassword();
    }
    protected void btnCancel_Click(object sender, EventArgs e)
    {
        _controller.RedirectToRelevantView();
    }

    public bool EnableDisableControl
    {
        get
        {
            return lblCurrentPassword.Visible;
        }
        set
        {
            lblCurrentPassword.Visible = value;
            txtCurrentPassword.Visible = value;
            txtCurrentPassword.ValueRequired = value;
        }
    }


    public List<SecurityQuestionInformation> SecurityQuestionList
    {
        set
        {
            ddlSecretQuestion.DataSource = value;
            ddlSecretQuestion.DataValueField = "ID";
            ddlSecretQuestion.DataTextField = "Question";
            ddlSecretQuestion.DataBind();
        }
    }

    public string Answer
    {
        get
        {
            return txtSecurityAns.Text;
        }
    }

    public int SelectedSecurityQuestionId
    {
        get
        {
            if (ddlSecretQuestion.Visible)
                return int.Parse(ddlSecretQuestion.SelectedValue);
            else
                return 0;
        }
    }

    public bool EnableDisableControlForFirstTimer
    {
        get
        {
            return ddlSecretQuestion.Visible;
        }
        set
        {
            lblSecurityQues.Visible = value;
            ddlSecretQuestion.Visible = value;
            lblAnswer.Visible = value;
            txtSecurityAns.Visible = value;
            btnCancel.Visible = !value;
        }
    }

}
